package com.control.mbtc.activitys;

import android.content.Context;
import android.content.Intent;
import androidx.annotation.NonNull;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import android.view.Menu;
import android.view.MenuItem;

import com.control.mbtc.R;
import com.control.mbtc.fragments.main.ChatFragment;
import com.control.mbtc.fragments.main.HomeC2cFragment;
import com.control.mbtc.fragments.main.HomeDealFragment;
import com.control.mbtc.fragments.main.HomeMarketFragment;
import com.control.mbtc.fragments.main.HomeWalletFragment;
import com.control.mbtc.utils.NavHelper;
import com.control.mbtc.utils.NavigationViewHelper;
import com.zzyd.common.app.AppActivity;

import butterknife.BindView;

public class MainActivity extends AppActivity implements NavHelper.OnTabChangedListener<Integer>, BottomNavigationView.OnNavigationItemSelectedListener {
    @BindView(R.id.navigationView)
    BottomNavigationView navigationView;
    /**
     * BottomNavigationView封装控制
     */
    private NavHelper<Integer> mNavHelper;

    /**
     * MainActivity显示方法
     * @param context context
     */
    public static void show(Context context) {
        context.startActivity(new Intent(context, MainActivity.class));
    }

    @Override
    protected int getContentLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    protected void initWidget() {
        super.initWidget();
        NavigationViewHelper.disableShiftMode(navigationView);
        mNavHelper = new NavHelper<>(this, getSupportFragmentManager(), R.id.lay_center, this);
        mNavHelper.add(R.id.action_hiangqing, new NavHelper.Tab<Integer>(HomeMarketFragment.class, R.string.title_hangqing))
                .add(R.id.action_jiaoyi, new NavHelper.Tab<Integer>(HomeDealFragment.class, R.string.title_jiaoyi))
                .add(R.id.action_c2c, new NavHelper.Tab<Integer>(HomeC2cFragment.class, R.string.title_C2C))
                .add(R.id.action_chat,new NavHelper.Tab<Integer>(ChatFragment.class,R.string.title_chat))
                .add(R.id.action_qianbao, new NavHelper.Tab<Integer>(HomeWalletFragment.class, R.string.title_qianbao));


        navigationView.setOnNavigationItemSelectedListener(this);
    }

    @Override
    protected void initData() {
        super.initData();
        Menu menu = navigationView.getMenu();
        menu.performIdentifierAction(R.id.action_hiangqing,0);
    }

    @Override
    public void onTabChanged(NavHelper.Tab<Integer> newTab, NavHelper.Tab<Integer> oldTab) {

    }

    @Override
    public boolean onNavigationItemSelected(@NonNull MenuItem item) {
        return mNavHelper.performClickMenu(item.getItemId());
    }
}
